home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / inter52f.zip / INT2WHLP.ZIP / INT2WHLP.INC < prev    next >
Text File  |  1996-10-05  |  36KB  |  931 lines

  1. (* INT2WHLP Pascal Program Include File *)
  2.  
  3. (*
  4.   Interrupt List -> WinHelp converter (c) 1994 by Christian Müller-Planitz
  5.   ------------------------------------------------------------------------
  6. *)
  7.  
  8. (* v. 1.18 *)
  9.  
  10. const
  11.   tableArraySize = 250; (* elements in table arrays *)
  12.  
  13. type
  14.   stringPtr = ^string;
  15.   categoryStringPtrArr = array['!'..#126] of stringPtr;
  16.   titleStringPtrArr = array[byte] of stringPtr;
  17.   stringListPtr = ^stringList;
  18.   stringList = record next: stringListPtr; s: string; end;
  19.     (* NB! The program relies on "next" being the first field *)
  20.   stringListPtrPtr = ^stringListPtr;
  21.   aliasStringType = string[119];
  22.   tableArray = array[1..tableArraySize] of integer;
  23.  
  24. var
  25.   flagStrings,categoryStrings,categoryKeyStrings: categoryStringPtrArr;
  26.   INTtitles: titleStringPtrArr;
  27.  
  28.   CONST InPath  : dirStr = '';
  29.     OutPath : dirStr = '';
  30.     TopicNo : Word = 0;
  31.     LastSection : String[3] = '';    { stores number of last processed int }
  32.     IntTopicStr : String[7] = '';    { stores handle to page with subfunctions of the int's}
  33.     filterFileName: pathStr = '';
  34.     filtered: boolean = false;
  35.     compression: string[19] = 'NO';
  36.     emptyString: string[1] = '';
  37.     noteString: string[5] = 'note';
  38.     noneString: string[7] = '(none)';
  39.     buildExpr: string = '';
  40.     secReg: string[9] = ' '; (* secReg[1] = ' ' *)
  41.     equStr: string[7] = ' Ax = ';
  42.     equStr2: string[3] = ' = ';
  43.     equBlanks: byte = 2;
  44.       (* These two variables can be changed to ' Ax=' and 0 by
  45.          program parameter -Q-. They control the format of search
  46.          strings as "INT nn AX = ahal" or "INT nn AX=ahal".
  47.          equStr[3] is assigned 'L', 'H', or 'X' by the program.
  48.       *)
  49.     tables: boolean = true; (* enables table cross referencing *)
  50.     backRef: boolean = false; (* disables the very first backward xref *)
  51.     missingTableCounter: word = 0;
  52.     missingTableLimit = 5; (* wait for user response when reached *)
  53.     indexColumns: integer = 1;
  54.     queuedEntry: string[127] = '';
  55.       (* stores an entry for the index, inserted by a call to insertQueued *)
  56.     notesCount: word = 0;    (* counts "Notes" entries in index *)
  57.     title: string[127] = ''; (* current "Notes" or "INT nn ... " *)
  58.     lastINTno: integer = -1;
  59.     firstAliasP: stringListPtr = NIL; (* aliases to be written to HPJ *)
  60.     nl: string[5] = '\par '; (* global NewLine string for AddTopic *)
  61.     indentIndex: string[7] = '\par   '; (* or '\par ' *)
  62.     insertCounter: integer = 0; (* counts inserted table references *)
  63.     tabTop: integer = 0; (* current top of table array *)
  64.     maxTabTop: integer = 0; (* highest value of currentTabTop *)
  65.     refTop: integer = 0; (* current top of reference array *)
  66.     maxRefTop: integer = 0; (* highest value of currentRefTop *)
  67.     warnings: word = 0; (* counts issued warnings *)
  68.  
  69. const
  70.   (* The following typed constants controls some program behaviors. They
  71.      can all be set under configuration file and program parameter control.
  72.      The configuration section [OPTIONS] uses keys with the same names as
  73.      the typed constants, and the program parameters are listed for each
  74.      constant.
  75.   *)
  76.   singlesInMain: boolean = false;
  77.     (* There are two levels in the Interrupts index: A main index
  78.        with an entry for each interrupt, and a page for each interrupt
  79.        number. If "singlesInMain" is true, the entry in the main index
  80.        refers directly to the interrupt text if there is only one entry
  81.        in the table for that interrupt, if  "singlesInMain" is false, the
  82.        entry in the main index refers to a page with only one field.
  83.        Controlled by program parameter -1.
  84.     *)
  85.   twoIndexes: boolean = true;
  86.     (* If "twoIndexes" is true, the program mantains two indexes,
  87.        "Interrupt Index" with all the topics in the Interrupt List, and
  88.        "Interrupts" as described above. If the flag is false, only the
  89.        latter index is created.
  90.        Controlled by program parameter -2.
  91.     *)
  92.   errorLog: boolean = false;
  93.     (* controles whether HCxx error messages are written to a log file,
  94.        or to the screen only.
  95.        Controlled by program parameter -E.
  96.     *)
  97.   indexHeaders: boolean = true;
  98.     (* controles whether or not a heading "INT nn" is inserted for every
  99.        new interrupt number in the "Interrupt Index". Ignored if
  100.        "twoIndexes" is false.
  101.        Controlled by program parameter -H.
  102.     *)
  103.   markKeys: boolean = true;
  104.     (* If true, keywords (like "See also:", "Notes:") are bolded, if
  105.        false, they are not.
  106.        Controlled by program parameter -M.
  107.     *)
  108.   releaseNo: integer = 41;
  109.     (* This variable can be used to control program behavior and thus
  110.        facilitate compilation of older releases of the Interrupt List.
  111.        Currently it is used to:
  112.        Inhibit table as separate topics and table cross references if
  113.          releaseNo<41.
  114.        Controlled by program parameter -R.
  115.     *)
  116.   scrollIndexTitle: boolean = true;
  117.     (* Windows have a non-scroll area with the window title. Index
  118.        windows have an initial title part describing List release
  119.        number and help file compile date (inserted by specifying
  120.        "specialClassification" in the call to procedure "NewHlpPage").
  121.        If "scrollIndexTitle" is true, only the general part of the
  122.        title is in the non-scroll region, thus opening more space for
  123.        the scrolling part. If the flag is false, the whole title field
  124.        is made non-scrolable.
  125.        Controlled by program parameter -S.
  126.     *)
  127.   tableWindow: boolean = true;
  128.     (* If true, tables activated from a "#nnnn" hotspot appear in a
  129.        secondary window, if fase, in the main window.
  130.        Controlled by program parameter -T.
  131.     *)
  132.   expandedIndex: boolean = true;
  133.     (* controls whether the Interrupt Index initialy pops up in expanded
  134.        or compressed format.
  135.        Controlled by program parameter -X.
  136.     *)
  137.   longKeys: boolean = true;
  138.     (* disables the long form of interrupt search keys if false (e.g.
  139.        disables "INT 03 AH = 09" so only the short form "03 09" is
  140.        available).
  141.        Controlled by program parameter -L.
  142.     *)
  143.  
  144. (* Help windows topic titles and identifiers: *)
  145.     (* The following text describes windows titles as defined by the "$"
  146.        footnotes and topic identifiers (context strings) as defined by
  147.        the "#" footnotes. The identifiers can be used to open the List
  148.        at a given position by an external call to WINHELP.
  149.  
  150. window title        identifier    text
  151.  
  152. Contents:        CONTENTS    Main index.
  153. Interrupt Index        idIndex        Total list, only if "twoIndexes" is true.
  154. Interrupts            idInterrupts    Main interrupt index.
  155. INT NN List        nn_0        Index for INT NN, nn are two hex digits.
  156. INT NN AHAL - <header>    nn_1        First entry about INT NN, the following
  157.                     entries have consecutive identifiers
  158.                     ... nn_9, nn_10, ... . Aliases for
  159.                     Interrupt List topics can be compiled
  160.                     and written to the Help Project file.
  161.                     These aliases can be used to identify
  162.                     any (unique) topic.
  163. Tables            idTables    Table index.
  164. NN AHAL <table title>    tnnnn        Table No. nnnn, nnnn are the four
  165.                     decimal digits from the List. Aliases
  166.                     can be compiled based on table position
  167.                     and title.
  168.                     NN and AHAL in the title are the
  169.                     interrupt number and the register
  170.                     contents (sub function) where the table
  171.                     is defined.
  172. FILELIST        1        The initial part of the Interrrupt List.
  173. <notes>            n        Other notes have consecutive numbers as
  174.                     identifiers.
  175. INTERRUP.1ST File    id1st        INTERRUP.1ST file window.
  176. none            idPartComp    Partial compilation popup window if
  177.                     parameter -f<name>.
  178. Filter Method        idFlt_meth    Filter Method if parameter -f<name>.
  179. Filter File        idFlt_file    Filter File if parameter -f<name>.
  180. Credits            idCredits    The Credits window.
  181. none        Compressed_Index    This identifier is used as a marker.
  182.  
  183. The identifiers mentioned above are reserved for program use. Titles and
  184. identifiers for other windows are defined in the configuration file.
  185.  
  186. The program maintains 6 browse chains, as defined by the "+" footnotes:
  187.  
  188. The "main" chain:
  189.     m:1    the Credits window.
  190.     m:2    the Contents window.
  191.     m:3    the Interrupt Index window provided "twoIndexes" is true.
  192.     m:4    the Interrupts window.
  193.     m:5    the Tables window provided "releaseNo" >= 41.
  194.     m:9    index windows included as window type 2.
  195.  
  196. The "list" chain:
  197.     l:0    the interrupt list sub index windows.
  198.  
  199. The "interrupt" chain:
  200.     i:0    the interrupt windows.
  201.  
  202. The "file" chain:
  203.     f:0    files included by the program or as window type 1.
  204.  
  205. The "table" chain:
  206.     t:0    the table windows provided "releaseNo" >= 41.
  207.  
  208. The "ports" chain:
  209.     p:0    the sub windows compiled from window type 2 inclusion.
  210.  
  211. Window type 3 inclusions can link onto these chains or maintain their own
  212. chains under user control.
  213.  
  214. *)
  215.  
  216. (* Constants defining windows setup etc.
  217.    All the typed constants can be changed by the configuration file, and
  218.    some of them also by program parameters.
  219. *)
  220.  
  221. (* definitions for the *.HPJ file: *)
  222.     windowsTitle =     '"Ralf Brown''s Interrupt List"';
  223.     secWindowsTitle =  '"Interrupt List Tables"';
  224.     secWindow = 'ITW'; (* the name of the secondary window *)
  225.     mainW: string[5] = '>main'; (* or '' *)
  226.     tableW: string[((length(secWindow)+3) AND $FE) - 1] = '>'+secWindow;
  227.     windowsPosSize: string[21]   =   '';
  228.       (* or: '(xpos,ypos,width,heigth)' *)
  229.     secWindowsPosSize: string[21] =  '(43,0,980,1023)';
  230.       (* values must be defined for a secondary window *)
  231.     windowsMaximized = '0';      (* '0': no; '1': yes (overrides size) *)
  232.     windowsBackgr: string[19]    = ''; (* or: '(red,green,blue)' *)
  233.     windowsHdrBackgr: string[19] = ''; (* or: '(red,green,blue)' *)
  234.  
  235. (* definitions for fonts, attributes, and size: *)
  236.     headerFont: string[31]       = 'roman Times New Roman';
  237.       (* or 'swiss Arial' *)
  238.     textFont: string[31]         = 'modern Courier New';
  239.     deciPoints: word             = 90;
  240.       (* 10 times point size *)
  241.     headerDeciPoints: word       = 140;
  242.     header2ndDeciPoints: word    = 120;
  243.     headerAttrib =     '';       (*
  244.         \b   = bold
  245.         \i   = italics
  246.       *)
  247.     highlightInt =     '';       (* this attribute highlights specificly
  248.                        the "INT nn" part of the header *)
  249.     indent =           '1060';   (* left indent of header after line one *)
  250.       (* (in twips, twentieth of a point, 1/1440 of an inch) *)
  251.     dateSep =  '-';        (* for compile time YYYY-MM-DD string *)
  252.     timeSep =  ':';        (* for compile time H:MM string *)
  253.     (*.$define m_dd_yy *)  (* defines date format, default is yyyy-mm-dd *)
  254.     (*.$define d_mm_yy *)  (* defines date format if m_dd_yy is undefined *)
  255.     (*.$define yy_mm_dd *) (* defines date format to yy-mm-dd instead of
  256.                   yyyy-mm-dd if both m_dd_yy and d_mm_yy
  257.                   are undefined *)
  258.  
  259.   Var
  260.       ProcessTime    : Longint;
  261.       IndexFile      : Text;                    { stores one entry per int-number }
  262.       IntFile        : Text;                    { stores *all* section names }
  263.     { the function of these two files was reversed in version 1.15 }
  264.       SubIntFile     : Text;                    { stores all subfunctions of an int per page }
  265.       TableFile      : Text;                    { stores tables references (index) }
  266.       IntTopics      : Text;
  267.       TabTopics      : Text;
  268.       HPJ            : Text;                    { hlep compiler project file }
  269.       indexHeader    : string;                  { index and subindex header string }
  270.       compilationStr : string[159];             { compilation information }
  271.       TopicStr   : String[15];            { used in CheckKeyWords and ProcessList }
  272.       indexPages,indexRows: integer;
  273.       dateString: string[19];
  274.       fontSize, headerSize, header2ndSize: string[7];
  275.       aliasP,tableAliasP: stringListPtr;
  276.     (* aliases read from configuration file *)
  277.       aliasId,tableAliasId: string[19];
  278.       aliasString,tableAliasString: aliasStringType;
  279.       nextAliasPP: stringListPtrPtr;
  280.     (* stored aliases, to be written to the HPJ file *)
  281.       INTcounts: array[byte] of word;
  282.       currentDir,homeDir: dirStr;
  283.       currentTable: string[5];
  284.       lineCount  : word; (* for error report *)
  285.       tabArray: tableArray; (* tables found in current interrupt *)
  286.       refArray: tableArray; (* tables referenced in current interrupt *)
  287.  
  288.   Const
  289.     (* classification characters < '!' do not insert a classification string as
  290.        a keyword.
  291.     *)
  292.     InvalidClassification = '-'; (* don't insert classification string as keyword *)
  293.     nullClassification = #0;     (* no title as keyword *)
  294.     specialClassification = #1;  (* use indexHeader in header *)
  295.     tableClassification = #2;    (* insert '#' + currentTable as keyword *)
  296.  
  297. function readKeyWd: word;
  298. (* Calls BIOS to read the keyboard, returns scan code in hi and char. in lo *)
  299.   inline($B4/$00/ {mov ah,0}  $CD/$16 {int $16});
  300.  
  301. procedure wl(s: string);
  302. (* a substitute for single-string "writeln" to screen (or "output") (saves
  303.    20 bytes of code per call).
  304. *)
  305.   begin writeln(s) end;
  306.  
  307. procedure errorExit(msg: string; err: byte);
  308. (* prints "msg" to screen and halts with errorlevel "err" *)
  309.   begin wl(msg); halt(err); end;
  310.  
  311. function exist(filename: pathStr): boolean;
  312. (* check the existance of "filename" *)
  313.   var b: boolean; t: text;
  314.   begin
  315. (*$I-*)
  316.     assign(t,filename);
  317.     reset(t);
  318.     b:=IOresult=0;
  319.     if b then close(t);
  320.     exist:=b;
  321. (*$I+*)
  322.   end; (* function exist *)
  323.  
  324. procedure defaultDir(var fileName: pathStr; var default: dirStr);
  325. (* if fileName has no drive, root, or current specification, then insert the
  326.    default directory.
  327. *)
  328.   begin
  329.     if (fileName[2]<>':') AND (fileName[1]<>'\') AND (fileName[1]<>'.') then
  330.       insert(default,filename,1);
  331.     fileName:=fExpand(fileName);
  332.   end; (* procedure defaultDir *)
  333.  
  334. (* Some of the following procedures are Windows getPrivateProfileXxx-like
  335.    routines to search the configuration file. If INT2WHLP.CFG is not found
  336.    in the current directory or in INT2WHLP.EXE's home directory, or if
  337.    the section or entry is not found in the file, the "value" parameter is
  338.    unchanged, otherwise the section/entry value is assigned to "value". A
  339.    boolean value is considered false if it is 0, and true otherwise.
  340. *)
  341.  
  342. function findProfile(var configFile: text; var section: dirStr): boolean;
  343. (* opens INT2WHLP.CFG on configFile and reads up to the specified section.
  344.    findProfile returns true if the configuration file was located, false
  345.    otherwise. If eof(configFile) returns true after a successful call
  346.    to findProfile this indicates that the section was not found, or it was
  347.    empty and last.
  348. *)
  349.   var i,l: integer; s: string;
  350.   begin
  351. (*$I-*)
  352.     findProfile:=false; (* suggest configuration file absent *)
  353.     if exist(progName+'.CFG') then assign(configFile,progName+'.CFG')
  354.     else assign(configFile,homeDir+progName+'.CFG');
  355.     reset(configFile);
  356.     if IOresult<>0 then exit;
  357.     findProfile:=true;
  358.     i:=1;
  359.     l:=length(section);
  360.     if l=0 then exit; (* we will interpret section='' as "open only" *)
  361.     while (i<=l) AND NOT eof(configFile) do begin
  362.       readln(configFile,s);
  363.       i:=1;
  364.       if (length(s)>=l+2) AND (s[1]='[') AND (s[l+2]=']') then
  365.     while (i<=l) AND (upcase(section[i])=upcase(s[succ(i)])) do inc(i);
  366.     end; (* while i<=l ... *)
  367. (*$I+*)
  368.   end; (* procedure findProfile *)
  369.  
  370. procedure profileList(section: dirStr; var listP: stringListPtr);
  371. (* reads all the entries in the specified section to a linked list and
  372.    assigns the beginning of the list to listP. Empty lines and lines
  373.    starting with a semicolon (;) are ignored.
  374. *)
  375.   label done,doneNC;
  376.   var listPP: ^stringListPtr; s: string; configFile: text;
  377.   begin
  378.     listPP:=@listP;
  379.     if NOT findProfile(configFile,section) then goto doneNC;
  380.       (* no configuration file *)
  381.     while NOT eof(configFile) do begin
  382.       readln(configFile,s);
  383.       if (s<>'') AND (s[1]<>';') then begin
  384.     if s[1]='[' then goto done;
  385.     getMem(listPP^,length(s)+1+sizeOf(pointer));
  386.     listPP^^.s:=s;
  387.     listPP:=@listPP^^.next;
  388.       end; (* if (s<>'')... *)
  389.     end; (* while NOT eof() *)
  390.   done:
  391.     close(configFile);
  392.   doneNC:
  393.     listPP^:=NIL;
  394.   end; (* procedure profileList *)
  395.  
  396. procedure freeStringRec(var p: stringListPtr);
  397. (* updates p to point to the next record, and frees the current one *)
  398.   var p1: stringListPtr;
  399.   begin
  400.     if p=NIL then exit;
  401.     p1:=p;
  402.     p:=p1^.next;
  403.     freeMem(p1,length(p1^.s)+1+sizeOf(pointer));
  404.   end; (* procedure freeStringRec *)
  405.  
  406. procedure profileString(section, entry: dirStr; var value: string;
  407.   bufferLen: integer);
  408.   label done;
  409.   var i,l: integer; s: string; configFile: text;
  410.   begin
  411. (*$I-*)
  412.     if (section='') OR (entry='') then exit;
  413.     if NOT findProfile(configFile,section) then exit;
  414.       (* no configuration file *)
  415.     i:=1;
  416.     l:=length(entry);
  417.     while (i<=l) AND NOT eof(configFile) do begin
  418.       readln(configFile,s);
  419.       if (s<>'') AND (s[1]='[') then goto done;
  420.       i:=1;
  421.       if (length(s)>l) AND (s[succ(l)]='=') then
  422.     while (i<=l) AND (upcase(entry[i])=upcase(s[i])) do inc(i);
  423.     end; (* while i<=l ... *)
  424.     if i>l then value:=copy(s,succ(i),bufferLen);
  425.   done:
  426.     close(configFile);
  427. (*$I+*)
  428.   end; (* procedure profileString *)
  429.  
  430. procedure profileInt(section, entry: dirStr; var value: integer);
  431.   var i,j: integer; s: string[19];
  432.   begin
  433.     s:='';
  434.     profileString(section,entry,s,pred(sizeOf(s)));
  435.     if s='' then exit;
  436.     val(s,i,j);
  437.     if j=0 then value:=i;
  438.   end; (* procedure profileInt *)
  439.  
  440. procedure profileBoolean(section, entry: dirStr; var value: boolean);
  441.   var i: integer;
  442.   begin
  443.     i:=ord(value);
  444.     profileInt(section,entry,i);
  445.     value:=i<>0;
  446.   end; (* procedure profileBoolean *)
  447.  
  448. procedure scan(line: string; var spa: categoryStringPtrArr);
  449. (* scans lines with format "xxx a - definition a, A - definition A" and
  450.    allocates memory and stores the definitions at appropriate index in spa.
  451. *)
  452.   var
  453.     p: integer;
  454.     c: char;
  455.     ok: boolean;
  456.   begin
  457.     repeat
  458.       p:=pos(' - ',line);
  459.       if p=0 then exit;
  460.       if p>1 then c:=line[p-1];
  461.       ok:=((p=2) OR ((p>2) AND (line[p-2]<=' '))) AND (c>' ') AND (c<#127);
  462.       delete(line,1,p+2);
  463.       if ok then begin
  464.     p:=pos(' - ',line);
  465.     if p=0 then p:=length(line)+1 else dec(p,2);
  466.     while line[p-1]<=' ' do dec(p);
  467.     if line[p-1]=',' then dec(p);
  468.     getmem(spa[c],p);
  469.     spa[c]^:=copy(line,1,p-1);
  470.     delete(line,1,p);
  471.       end; (* if ok *)
  472.     until false; (* terminated by exit *)
  473.   end; (* procedure scan *)
  474.  
  475. procedure check1st(var s: string);
  476. (* scans s for the occurence of 'INTERRUP.1ST' and inserts xref to id1st.
  477.    Letter case is ignored.
  478. *)
  479.   var p: byte; s1: string[119];
  480.   begin
  481.     s1[0]:=s[0];
  482.     for p:=1 to length(s) do s1[p]:=upcase(s[p]);
  483.     p:=pos('INTERRUP.1ST',s1);
  484.     if p<>0 then begin
  485.       insert('}{\v id1st}',s,p+12);
  486.       insert('{\uldb ',s,p);
  487.     end; (* if p<>0 *)
  488.   end; (* procedure check1st *)
  489.  
  490. procedure getINTtitle(var line: string; var titles: titleStringPtrArr);
  491. (* allocates memory and copies a line starting with "INT nn " to titles[nn]^ *)
  492.   type (* for type casts *)
  493.     lineRec = record l: byte; INT: longint; nn: word; spc: char; end;
  494.     hexRec = record l: byte; dollar: char; nn: word; end;
  495.   const
  496.     intC = ord('I')+ord('N')*$100+ord('T')*$10000+ord(' ')*$1000000;
  497.     intNumber: string[3] = '$nn'; (* preset length to 3 and [1] to '$' *)
  498.   var
  499.     lineR: lineRec absolute line; (* for typecast *)
  500.     intR: hexRec absolute intNumber; (* for typecast *)
  501.     n,j: integer;
  502.   begin
  503.     if (length(line)<8) OR (lineR.spc<>' ') OR (lineR.INT<>intC) then exit;
  504.     intR.nn:=lineR.nn; (* two characters typecasted to a word *)
  505.     val(intNumber,n,j);
  506.     if j<>0 then exit;
  507.     getmem(titles[n],succ(length(line)));
  508.     titles[n]^:=line;
  509.   end; (* procedure getINTtitle *)
  510.  
  511. procedure getNextAlias(var aliasP: stringListPtr;
  512.    var aliasId, aliasString: string);
  513. (* extract an alias string from the heap and free the heap memory *)
  514.   var n: integer;
  515.   begin
  516.     aliasString:='';
  517.     if aliasP=NIL then exit;
  518.     aliasString:=aliasP^.s;
  519.     freeStringRec(aliasP); (* free memory and update aliasP *)
  520.     n:=pos('=',aliasString);
  521.     if n<2 then errorExit('Missing alias Id in '+aliasString,aliasErr);
  522.     if n>pred(sizeOf(aliasId)) then errorExit('Alias Id too long in '
  523.       +aliasString,aliasErr);
  524.     aliasId:=copy(aliasString,1,n);
  525.     delete(aliasString,1,n);
  526.   end; (* procedure getNextAlias *)
  527.  
  528. procedure saveAlias(var aPP: stringListPtrPtr; s: dirStr);
  529. (* allocates memory on the heap, stores information, and updates aPP *)
  530.   begin
  531.     getmem(aPP^,length(s)+1+sizeOf(pointer));
  532.     aPP^^.next:=NIL;
  533.     aPP^^.s:=s;
  534.     aPP:=@aPP^^.next
  535.   end; (* procedure saveAlias *)
  536.  
  537. procedure processAliasList(aP: stringListPtr);
  538.   begin
  539.     while aP<>NIL do begin
  540.       writeln(HPJ,aP^.s);
  541.       aP:=aP^.next;
  542.     end; (* while aP<>NIL *)
  543.   end; (* procedure processAliasList *)
  544.  
  545. procedure setTabs(var f: text; spaces, deciPoints, tabs: word);
  546. (* writes tab settings to file f, tabspacing approximately "spaces" character
  547.    columns width New Courier font with size 1/10*"deciPoints". Number of tab
  548.    settings = "tabs".
  549.    The tabs are valid until the next "\pard".
  550. *)
  551.   var i: integer; s: string[11];
  552.   begin
  553.     for i:=1 to tabs do begin
  554.       str(longint(i*spaces*deciPoints)*1170 DIV 1000,s);
  555.       (* tab spacing = (point size)*(column width)*11.70 *)
  556.     (* at least, this seems to fit pretty well *)
  557.       write(f,'\tx',s);
  558.     end; (* for i:=1 *)
  559.     writeln(f);
  560.   end; (* procedure setTabs *)
  561.  
  562. procedure writeIndex(s: string);
  563.   begin writeln(indexFile, s); end;
  564.  
  565.   procedure CreateHPJ;
  566.     var i,n: integer; bP: stringListPtr; s: pathStr;
  567.     begin
  568.       assign(HPJ, OutPath + hfName+'.HPJ');
  569.       rewrite(HPJ);
  570.       n:=0;
  571.       profileList('BUILDTAGS',bP);
  572.       if bP<>NIL then begin (* write [BuildTags] section *)
  573.     writeln(HPJ,'[BUILDTAGS]');
  574.     while bP<>NIL do begin
  575.       writeln(HPJ,bP^.s);
  576.       freeStringRec(bP); (* free memory and update bP *)
  577.     end; (* while bP<>NIL *)
  578.     writeln(HPJ);
  579.       end; (* if i>0 *)
  580.       profileList('BAGGAGE',bP);
  581.       if bP<>NIL then begin (* write [Baggage] section *)
  582.     writeln(HPJ,'[BAGGAGE]');
  583.     while bP<>NIL do begin
  584.       writeln(HPJ,bP^.s);
  585.       freeStringRec(bP); (* free memory and update bP *)
  586.     end; (* while bP<>NIL *)
  587.     writeln(HPJ);
  588.       end; (* if i>0 *)
  589.       s:=fExpand(OutPath);
  590.       if length(s)>3 then dec(s[0]); (* delete terminating '\' if not root *)
  591.       writeln(HPJ, '[OPTIONS]'#13#10'CONTENTS=CONTENTS'#13#10'COMPRESS=',compression);
  592.       writeln(HPJ,'REPORT=ON'#13#10'WARNING=2'#13#10'ROOT=',s);
  593.     (* warning=2 avoids the "Using old *.ph file" warning *)
  594.       if errorLog then writeln(HPJ,'ERRORLOG='+hfName+'.ERR');
  595.       if buildExpr<>'' then writeln(HPJ,'BUILD=',buildExpr);
  596.       writeln(HPJ, 'CITATION=Copied from Ralf Brown''s Interrupt List');
  597.       writeln(HPJ, 'COPYRIGHT='+hfName+' Layout: Christian Müller-Planitz');
  598.       s:='interrup.ico';
  599.       if NOT exist (s) then s:=HomeDir+'interrup.ico';
  600.       if NOT exist (s) then s:=InPath+'interrup.ico';
  601.       if exist(s) then writeln(HPJ, 'ICON=',s);
  602.       writeln(HPJ, #13#10'[CONFIG]'#13#10'CreateButton(`id_print'',`&Print'',`Print()'')');
  603.       writeln(HPJ, 'CreateButton(`id_copy'',`C&opy'',`CopyTopic()'')'#13#10'BrowseButtons()');
  604.       writeln(HPJ, 'CreateButton(`id_exit'',`E&xit'',`Exit()'')');
  605.       if twoindexes AND NOT expandedIndex then
  606.     writeln(HPJ, 'SaveMark(`Compressed_Index'')');
  607.       profileList('INTWINCONFIG',bP);
  608.       while bP<>NIL do begin (* copy [INTWINCONFIG] entries *)
  609.     writeln(HPJ,bP^.s);
  610.     freeStringRec(bP); (* free memory and update bP *)
  611.       end; (* while bP<>NIL *)
  612.       writeln(HPJ, #13#10'[WINDOWS]'#13#10'main='+windowsTitle+',',windowsPosSize,
  613.     ','+windowsMaximized+',',windowsBackgr,',',windowsHdrBackgr);
  614.       if tableWindow then writeln(HPJ, secWindow+'='+secWindowsTitle+',',
  615.     secWindowsPosSize,','+windowsMaximized+',',windowsBackgr,',',
  616.     windowsHdrBackgr);
  617.       writeln(HPJ, #13#10'[FILES]');
  618.     end;
  619.  
  620.   Procedure OpenRTF(VAR F: Text; Name: String);
  621.     begin
  622.      {$I-}
  623.       assign(F, OutPath + Name);
  624.       rewrite(F);
  625.      {$I+}
  626.       if IOResult <> 0 then errorExit('Error craeting '+OutPath+Name,rtfErr);
  627.  
  628.       writeln(HPJ, Name);
  629.  
  630.       writeln(F, '{\rtf1\pc \deff1{\fonttbl{\f0\f',headerFont,';}');
  631.       writeln(F, '{\f1\f',textFont,';}}');
  632.       writeln(F, '{\colortbl \red255\green0\blue0;\red0\green0\blue0;');
  633.       writeln(F, '\red0\green0\blue255;\red255\green255\blue255;}');
  634.       writeln(F, '\plain',fontSize,'\pard\keep');
  635.       TextRec(F).UserData[1]:=ord(false); (* mark as unused *)
  636.     end;
  637.  
  638.  
  639.   Procedure CloseRTF(VAR F: Text);
  640.     begin
  641.       writeln(F, '}');
  642.       close(F);
  643.     end;
  644.  
  645.   Procedure PageRTF(VAR F: Text);
  646.     begin
  647.       if boolean(TextRec(F).UserData[1]) then write(F, '\page')
  648.       else TextRec(F).UserData[1]:=ord(true);
  649.     end;
  650.  
  651.   Function HEX(b:byte):string;
  652.     Const h : array [0..15] of char = ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  653.     begin
  654.       Hex[0]:=#2; Hex[1]:=h[b shr 4]; Hex[2]:=h[b and 15];
  655.     end;
  656.  
  657.  
  658.   Procedure ReadLine(VAR F: Text; VAR S: String);
  659.     VAR q: Word;
  660.  
  661.     begin
  662.       readln(F, S);
  663.       q:= 1;
  664.       while q <= Length(s) do    { duplicate all '\' etc. }
  665.     begin
  666.       case s[q] of
  667.         '\', '{', '}': begin insert('\', s, q); inc(q); end;
  668.     (* v. 1.13: DOS framing characters are not transformed properly by
  669.        selecting the "pc" character set. We will transform single and double
  670.        horizontal frames to '-', vertical frames to '|', and all other
  671.        framing characters to '+'. Please note that some codepage 850 extended
  672.        characters are also transformed to '+'.
  673.     *)
  674.         #196, #205: s[q]:='-';
  675.         #179, #186: s[q]:='|';
  676.         #176..#223: s[q]:='+';
  677.         #128..#255: begin
  678.           insert(#39+HEX(ord(s[q])), s, q+1);
  679.           s[q] := '\';
  680.           Inc(q,3);
  681.         end; (* case #128..#255 *)
  682.       end; (* case s[q] of *)
  683.       if q>=255 then begin
  684.         writeln('Too many graphic characters in line ', lineCount);
  685.         ErrorExit('Please edit the file and try again', formatErr);
  686.       end; (* if q>255 *)
  687.       Inc(q);
  688.     end; (* while q>=length(s) *)
  689.  
  690.     end;
  691.  
  692.  
  693.  
  694.   Procedure OutLN(VAR F: Text; S : String);
  695.     begin
  696.       writeln(F, '\par ', S);
  697.     end;
  698.  
  699.  
  700.   Procedure Intro;
  701.     begin
  702.       wl(#10'Interrupt List-WinHelp preprocessor '+progname+' version '+progvers);
  703.       wl(copyright);
  704.       wl(e_mail+#13#10);
  705.       wl('Use "'+progname+' ?" for help.'#13#10);
  706.     end;
  707.  
  708.   Procedure Explain;
  709.     begin
  710.       wl('This program converts the Interrupt List written by Ralf Brown to a RTF-Format');
  711.       wl('that is used as an input format by the Microsoft WinHelp compiler.'#10);
  712.  
  713.       wl('In order to generate a Windows 3.1 helpfile you need the WinHelp compiler');
  714.       wl('"HC31.EXE", which is distributed with almost all Windows compilers and which');
  715.       wl('is also available on many Internet sites and FIDO BBS systems.'#10);
  716.  
  717.       wl('Please note that you also need a fast computer and a *lot* of free space on');
  718.       wl('your harddrive, see the file I2W-HINT.TXT. If you want to find out whether you');
  719.       wl('are able to compile a RTF file, I recommend that you experiment with the files');
  720.       wl('in the I2W-TEST.ZIP subpackage.'#10);
  721.  
  722.       wl('After this program finishes, you have to invoke the WinHelp compiler with');
  723.       writeln('the command "HC31 ',hfName,'.HPJ".'#10);
  724.  
  725.       wl('For more information about '+progName+' program options and configuration file,');
  726.       wl('read the I2W-OPT.TXT and I2W-CFG.TXT files.'#10);
  727.  
  728.       wl('Have fun ! --CMP'#10);
  729.  
  730.       wl('P.S. If you have problems building the helpfile or if you simply want to write');
  731.       wl('     an e-mail to me, please write to:');
  732.       wl('     '+e_mail);
  733.       halt(0);
  734.     end;
  735.  
  736. procedure initializeArrays;
  737.   var i: integer; ch: char;
  738.   begin
  739.     for ch:='!' to #126 do begin (* default to empty string *)
  740.       flagStrings[ch]:=@emptyString;
  741.       categoryStrings[ch]:=@emptyString;
  742.       categoryKeyStrings[ch]:=@emptyString;
  743.     end; (* for ch:='!' *)
  744.     categoryStrings['!']:=@noteString;
  745.     categoryStrings['-']:=@noneString;
  746.     for i:=$00 to $FF do begin INTcounts[i]:=0; INTtitles[i]:=@emptyString; end;
  747.   end; (* procedure initializeArrays *)
  748.  
  749. procedure findDateAndCopyright;
  750.   var a,b,c,d: word; s,ss: string[99]; t: text;
  751.   begin
  752.     getDate(a,b,c,d);
  753.     (*$ifdef m_dd_yy *)
  754.       str(b*1000000+(c*1000+a MOD 100),dateString);
  755.       dateString[length(dateString)-5]:=dateSep;
  756.       dateString[length(dateString)-2]:=dateSep;
  757.     (*$else*)
  758.       (*$ifdef d_mm_yy *)
  759.     str(c*1000000+(b*1000+a MOD 100),dateString);
  760.     dateString[length(dateString)-5]:=dateSep;
  761.     dateString[length(dateString)-2]:=dateSep;
  762.       (*$else*)
  763.     str(a*1000000+(b*1000+c),dateString);
  764.     dateString[5]:=dateSep;
  765.     dateString[8]:=dateSep;
  766.     (*$ifdef yy_mm_dd *) delete(dateString,1,2); (*$endif*)
  767.       (*$endif*)
  768.     (*$endif*)
  769.     getTime(a,b,c,d);
  770.     str((a*1000+b)+100000,s);
  771.     s[4]:=timeSep;
  772.     s[1]:=' ';
  773.     if a<10 then delete(s,2,1);
  774.     dateString:=dateString+' -'+s;
  775.   (*$I-*)
  776.     assign(t,InPath+'interrup.lst');
  777.     reset(t);
  778.     if IOresult<>0 then begin
  779.       assign(t,InPath+'interrup.a');
  780.       reset(t);
  781.       if IOresult<>0 then
  782.     errorExit('Unable to open INTERRUP file in directory '+InPath,fileErr);
  783.     end; (* if IOresult<>0 *)
  784.   (*$I+*)
  785.     ReadLine(t,s);
  786.     ReadLine(t,ss);
  787.     close(t);
  788.     for a:=1 to 2 do begin
  789.       b:=pos(#9,s); (* remove two wide areas of whitespace *)
  790.       if b<>0 then while s[b]=#9 do delete(s,b,1)
  791.       else begin
  792.     b:=pos('        ',s);
  793.     if b<>0 then while s[b]=' ' do delete(s,b,1)
  794.       end; (* else *)
  795.       if b<>0 then insert('      ',s,b); (* insert 6 spaces instead *)
  796.     end; (* for a:=1 *)
  797.     indexHeader:='{\keep '+s+#13#10'\par{'+header2ndSize+' '+ss+'}'#13#10'\par';
  798.     if scrollIndexTitle then indexHeader:=indexHeader+'\pard';
  799.     indexHeader:=indexHeader+#13#10'\par}';
  800.     compilationStr:=progName+' v. '+progVers+' compilation.'#13#10'\par '
  801.       +hfName+'.HLP compiled '+dateString+'.';
  802.     if filtered then compilationStr:=compilationStr
  803.       +' {\ul Partial compilation.}{\v idPartComp}';
  804.   end; (* procedure findDateAndCopyright *)
  805.  
  806. procedure interpretParameters;
  807. (* interprets program parameters and parts of the configuration file *)
  808.   var i,argVal: integer; s: string[79]; blanks: boolean;
  809.   procedure copyParam(var dest: string; len: byte);
  810.     begin dest:=copy(s,3+ord(s[3]=':'),len); end;
  811.   procedure getArgVal;
  812.     (* assigns value of argument, or $8000, to argVal *)
  813.     var i: integer; st: string[9];
  814.     begin
  815.       copyParam(st,9);
  816.       val(st,argVal,i);
  817.       if i<>0 then argVal:=integer($8000);
  818.     end; (* procedure getArgVal in interpretParameters *)
  819.   function getBool: boolean;
  820.     begin getBool:=(length(s)<3) OR (s[3]<>'-'); end;
  821.   procedure setSize(var fs: string; dp: word);
  822.     (* converts decipoints to an RTF halfpoint font size string *)
  823.     begin
  824.       str(dp DIV 5,fs);
  825.       insert('\fs',fs,1);
  826.     end; (* procedure setSize in interpretParameters *)
  827.  
  828.   begin
  829.     blanks:=true;
  830.     (* first, check configuration file *)
  831.     profileString('OPTIONS','build',buildExpr,pred(sizeOf(buildExpr)));
  832.     profileString('OPTIONS','compression',compression,pred(sizeOf(compression)));
  833.     profileString('OPTIONS','filterFile',filterFileName,pred(sizeOf(filterFileName)));
  834.     profileBoolean('OPTIONS','singlesInMain',singlesInMain);
  835.     profileBoolean('OPTIONS','twoIndexes',twoIndexes);
  836.     profileBoolean('OPTIONS','errorLog',errorLog);
  837.     profileBoolean('OPTIONS','indexHeaders',indexHeaders);
  838.     profileInt('OPTIONS','indexColumns',indexColumns);
  839.     profileBoolean('OPTIONS','markKeys',markKeys);
  840.     profileBoolean('OPTIONS','equalBlanks',blanks);
  841.     profileInt('OPTIONS','releaseNo',releaseNo);
  842.     profileBoolean('OPTIONS','scrollIndexTitle',scrollIndexTitle);
  843.     profileBoolean('OPTIONS','tableWindow',tableWindow);
  844.     profileBoolean('OPTIONS','expandedIndex',expandedIndex);
  845.     profileBoolean('OPTIONS','longKeys',longKeys);
  846.     (* second, check parameters *)
  847.     for i:=1 to paramCount do begin
  848.       s:=paramStr(i);
  849.       case s[1] of
  850.     '/','-': begin
  851.       if length(s)=1 then errorExit(
  852.         'Missing option after "'+s+'"',paramErr);
  853.       case upcase(s[2]) of
  854.         'B': copyParam(buildExpr,pred(sizeOf(buildExpr)));
  855.         (* legal: any .HPJ [OPTIONS] build= expression *)
  856.         'C': begin
  857.           copyParam(compression,pred(sizeOf(compression)));
  858.         (* legal: 0, 1, no, yes, low, medium, high. Not checked *)
  859.           if compression='' then compression:='YES';
  860.         (* default if "-c" or "-c:" is specified *)
  861.         end; (* case 'C' *)
  862.         'F': begin
  863.           copyParam(filterFileName,pred(sizeOf(filterFileName)));
  864.           if filterFileName='' then errorExit(
  865.         'No filter file name specified after "'+s+'"',fileErr);
  866.           filtered:=true;
  867.         end; (* case 'F' *)
  868.         '1': singlesInMain:=getBool;
  869.         '2': twoIndexes:=getBool;
  870.         'E': errorLog:=getBool;
  871.         'H': indexHeaders:=getBool;
  872.         'I': begin getArgVal; indexColumns:=argVal; end;
  873.         'M': markKeys:=getBool;
  874.         'Q': blanks:=getBool;
  875.         'R': begin getArgVal; releaseNo:=argVal; end;
  876.         'S': scrollIndexTitle:=getBool;
  877.         'T': tableWindow:=getBool;
  878.         'X': expandedIndex:=getBool;
  879.         'L': longKeys:=getBool;
  880.         else errorExit('Unknown option: '+s,paramErr);
  881.       end; (* case upcase(s[2] of *)
  882.     end; (* case '/','-' *)
  883.     else begin
  884.       if InPath='' then InPath:=s
  885.       else if OutPath='' then OutPath:=s
  886.       else errorExit('Too many parameters: '+s,paramErr);
  887.     end; (* case else *)
  888.       end; (* case s[1] of *)
  889.     end; (* for i:=1 *)
  890.     (* if file paths were not program parameters, try configuration file *)
  891.     if InPath='' then profileString('FILES','InPath',InPath,pred(sizeOf(InPath)));
  892.     if OutPath='' then profileString('FILES','OutPath',OutPath,pred(sizeOf(OutPath)));
  893.     (* read windows settings from configuration file *)
  894.     profileString('CONFIG','pos and size',windowsPosSize,pred(sizeOf(windowsPosSize)));
  895.     profileString('CONFIG','secondary pos and size',
  896.       secWindowsPosSize,pred(sizeOf(secWindowsPosSize)));
  897.     profileString('CONFIG','background',windowsBackgr,pred(sizeOf(windowsBackgr)));
  898.     profileString('CONFIG','header background',windowsHdrBackgr,pred(sizeOf(windowsHdrBackgr)));
  899.     profileString('CONFIG','header font',headerFont,pred(sizeOf(headerFont)));
  900.     profileString('CONFIG','text font',textFont,pred(sizeOf(textFont)));
  901.     profileInt('CONFIG','deciPoints',integer(deciPoints));
  902.     profileInt('CONFIG','header deciPoints',integer(headerDeciPoints));
  903.     profileInt('CONFIG','header 2nd deciPoints',integer(header2ndDeciPoints));
  904.     (* update other values *)
  905.     indexRows:=16; (* in most cases *)
  906.     indexPages:=1; (* in two cases *)
  907.     case indexColumns of
  908.       1: indexRows:=256;
  909.       4: indexPages:=4;
  910.       8: indexPages:=2;
  911.       16: ; (* already ok *)
  912.       else errorExit('Illegal index columns, only 1, 4, 8, or 16 accepted',
  913.     paramErr);
  914.     end; (* case indexColumns of *)
  915.     if NOT blanks then begin
  916.       equStr[4]:='=';
  917.       equStr[0]:=#4; (* equStr = ' Ax=' *)
  918.       equStr2[1]:='=';
  919.       equStr2[0]:=#1; (* equStr2 = '=' *)
  920.       equBlanks:=0;
  921.     end; (* if NOT blanks *)
  922.     setSize(fontSize,deciPoints);
  923.     setSize(headerSize,headerDeciPoints);
  924.     setSize(header2ndSize,header2ndDeciPoints);
  925.     filtered:=filterFileName<>'';
  926.     if NOT indexHeaders then indentIndex:=nl;
  927.     if releaseNo<41 then begin tables:=false; tableWindow:=false; end;
  928.     if NOT tableWindow then begin mainW:=''; tableW:=''; end;
  929.   end; (* procedure interpretParameters *)
  930.  
  931.